home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 9 / FM Towns Free Software Collection 9.iso / t_os / shell / tsbgex / src / fish / fish.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-16  |  4.1 KB  |  187 lines

  1. #include "fish.h"
  2.  
  3. #define TIMER    2
  4.  
  5. #include "collaris.h"
  6. #define COLLARIS_ANIME    9
  7. #define COLLARIS_Y    150
  8. #define COLLARIS_DX  1
  9. #define COLLARIS_DT    1
  10. #define COLLARIS_SIZE    (collaris_width*collaris_height)
  11. unsigned char collaris_save[COLLARIS_SIZE * sizeof (short)];
  12.  
  13. #include "blueking.h"
  14. #define BLUEKING_ANIME    8
  15. #define BLUEKING_Y    70
  16. #define BLUEKING_DX  2
  17. #define BLUEKING_DT    1
  18. #define BLUEKING_SIZE    (blueking_width*blueking_height)
  19. unsigned char blueking_save[BLUEKING_SIZE * sizeof (short)];
  20.  
  21. struct fish fishes[] = {
  22.   {    COLLARIS_ANIME, COLLARIS_Y, COLLARIS_DX, COLLARIS_DT,
  23.     collaris_width, collaris_height, collaris_n_raster,
  24.     collaris_colors, collaris_color16, collaris_color4,
  25.     collaris_rasters, collaris_save,
  26.   },
  27.   { BLUEKING_ANIME, BLUEKING_Y, BLUEKING_DX, BLUEKING_DT,
  28.     blueking_width, blueking_height, blueking_n_raster,
  29.     blueking_colors, blueking_color16, blueking_color4,
  30.     blueking_rasters, blueking_save,
  31.   }
  32.  };
  33. #define N_FISH (sizeof fishes / sizeof (struct fish))
  34. #define N_FISH_AT_ONCE    2
  35.  
  36. int fish_first = TRUE, fish_count = 1;
  37. int timer = TIMER;
  38. int anime1 = COLLARIS_ANIME;
  39. int ypos1 = COLLARIS_Y;
  40. int dx1 = COLLARIS_DX;
  41. int dt1 = COLLARIS_DT;
  42. int anime2 = BLUEKING_ANIME;
  43. int ypos2 = BLUEKING_Y;
  44. int dx2 = BLUEKING_DX;
  45. int dt2 = BLUEKING_DT;
  46.  
  47. void fishmain()
  48. {
  49.     int n;
  50.     struct fish *p;
  51.     static int id = 0;
  52.     extern int aplid, active, restart, unmapped;
  53.     extern short vramseg;
  54.     extern int pixel, vheight, dwidth;
  55.     extern int _setfs();
  56.     extern void mkcolor(), draw16(), draw4(), map();
  57.  
  58.     if (!active)
  59.         return;
  60.  
  61.     if (fish_first){
  62.         fishes[0].cnt_init = anime1;
  63.         fishes[0].y = ypos1;
  64.         fishes[0].dx = dx1;
  65.         fishes[0].dt = dt1;
  66.         fishes[1].cnt_init = anime2;
  67.         fishes[1].y = ypos2;
  68.         fishes[1].dx = dx2;
  69.         fishes[1].dt = dt2;
  70.     }
  71.     /* speed control timer */
  72.     if (--fish_count > 0)
  73.         return;
  74.     fish_count = timer;
  75.  
  76.     _setfs(vramseg);
  77.     if (restart){
  78.         restart = FALSE;
  79.         p = fishes;
  80.         n = N_FISH;
  81.         while (--n >= 0){
  82.             p->index = 0;
  83.             p->cnt = 1;
  84.             p->timer = 1;
  85.             p->win.x = -p->width + 1;
  86.             p->win.w = p->width;
  87.             p->win.h = p->h;
  88.             p->win.save = p->save;
  89.             p->win.owner = (void *)p;
  90.             p->win.mapped = FALSE;
  91.             if (pixel == 16){        /* 15bit-color */
  92.                 p->w = p->width + p->width;    /* byte */
  93.                 p->x_max = dwidth - 1;
  94.                 p->color = (unsigned char *)p->color16;
  95.                 if (vheight < 512)
  96.                     p->win.y = p->y;
  97.                 else
  98.                     p->win.y = p->y + (p->y >> 1);    /* x 1.5 */
  99.                 p->win.draw = draw16;
  100.             } else if (pixel == 4){    /* 4bit-color */
  101.                 p->w = p->width;        /* byte */
  102.                 p->x_max = dwidth - 1;
  103.                 mkcolor(p->n_color, p->color16, p->color4);
  104.                 p->color = p->color4;
  105.                 if (vheight < 1024)
  106.                     p->win.y = p->y * 2;
  107.                 else
  108.                     p->win.y = p->y * 3;
  109.                 p->win.draw = draw4;
  110.             }
  111.             p->save_size = p->w * p->h;
  112.             p->win.size = p->save_size;
  113.             if (fish_first){
  114.                 p->win.aplid = aplid;
  115.                 winCreate(&p->win);
  116.             }
  117.             winMap(&p->win);
  118.             p++;
  119.         }
  120.         id = 0;
  121.     }
  122.     if (fish_first)
  123.         fish_first = FALSE;
  124.         
  125.     if (unmapped)
  126.         map(TRUE);
  127.  
  128.      if ((n = N_FISH) > N_FISH_AT_ONCE)
  129.          n = N_FISH_AT_ONCE;
  130.      while (--n >= 0){
  131.         p = fishes + id;
  132.         if (--p->timer == 0){ /* fish speed control timer */
  133.             p->timer = p->dt;
  134.             winMove(&p->win, p->win.x + p->dx, p->win.y);
  135.             if (p->win.x > p->x_max)
  136.                 winMove(&p->win, -p->width+1, p->win.y);
  137.             if (--p->cnt == 0){ /* animation counter */
  138.                 p->cnt = p->cnt_init;
  139.                 if (++p->index == p->n_raster)
  140.                     p->index = 0;
  141.             }
  142.         }
  143.         if (++id == N_FISH)
  144.             id = 0;
  145.     }
  146. }
  147.  
  148. void fish_init()
  149. {
  150.     int i;
  151.     struct fish *p;
  152.     
  153.     for (i = 0, p = fishes; i < N_FISH; i++, p++)
  154.         p->index = -1;
  155. }
  156.  
  157. void map(int map)
  158. {
  159.     int i;
  160.     struct fish *p;
  161.     extern int unmapped;
  162.     
  163.     for (i = 0, p = fishes; i < N_FISH; i++, p++){
  164.         if (p->index >= 0){
  165.             if (map)
  166.                 winMap(&p->win);
  167.             else
  168.                 winUnmap(&p->win);
  169.         }
  170.     }
  171.     unmapped = !map;
  172. }
  173.  
  174. void terminate()
  175. {
  176.     int i;
  177.     struct fish *p;
  178.     
  179.     for (i = 0, p = fishes; i < N_FISH; i++, p++){
  180.         if (p->index >= 0){
  181.             winUnmap(&p->win);
  182.             winDestroy(&p->win);
  183.             p->index = -1;
  184.         }
  185.     }
  186. }
  187.